# -*- coding: utf-8 -*-
# @Author: QX
# @File: ReadExcel.py
import pandas
def pandas_read_excel_list(filepath,sheetname):
    # 读取指定路径和工作表名的 Excel 文件数据
    data = pandas.read_excel(filepath,sheet_name=sheetname)
    #用空字符串来填充数据中的NaN
    data = data.fillna('')
    #将数据转为list
    datalist = data.values.tolist()
    return(datalist)

def pandas_read_excel_dict(filepath,sheetname):
    data = pandas.read_excel(filepath,sheet_name=sheetname)
    data = data.where(data.notnull(),'')
    datadict = data.to_dict(orient='records')
    return(datadict)

if __name__ == '__main__':
    filepath=r'D:\appreadhome\examples\excelcase\kaoyanbang.xlsx'
    sheetname='Sheet2'
    print(pandas_read_excel_list(filepath, sheetname))
    print(pandas_read_excel_dict(filepath, sheetname))